'use strict';
app.service('forgetPasswordService',['$http','$q','utilService',function($http,$q,utilService){

    this.forgetPasswordPhone = function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'retrieve/password/phone',
            data:$scope.pwdPhone,
            method:"PUT"
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }


    this.getMobilePhoneCode = function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'getPhoneCodePwd',
            params:{mobilePhone:$scope.pwdPhone.phone}
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        });
        return deferred.promise;
    }

    this.getEmailCode = function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'send/email',
            params:{email:$scope.pwdEmail.email}
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        });
        return deferred.promise;
    }

    this.forgetPasswordEmail = function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'retrieve/password/email',
            data:$scope.pwdEmail,
            method:"PUT"
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }
}]);